<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">

#table{
	position: absolute;
	left:20px;
	top:150px;
}

#table2{
	position: absolute;
	right:70px;
	top:150px;
}

</style>
</head>

<body style="font-family:Arial, Helvetica, sans-serif">

<h1>Shop Ranking Last Week</h1>
<p><a href="http://<?php echo SERVER_IP_COMM;?>/caaudit/circle" target="_blank">Generate Ranking Again </a></p>

<a href="http://<?php echo SERVER_IP_COMM;?>/salesmonitor/repair-ranking" target="_blank">Check Repair Rank </a><br />
<br />
<div id = 'table'>
<table width="1300" border="0" cellspacing="1" cellpadding="5" style="background:#333">

  <tr>
  	<th bgcolor="#FFFFFF" scope="col" >&nbsp;</th>
    <th bgcolor="#FFFFFF" scope="col" >This Week Rank</th>
    <th bgcolor="#FFFFFF" scope="col" >Shop</th>
    <th bgcolor="#FFFFFF" scope="col" width="100" ><?php echo $this->strLastWeek;?></th>
    <th bgcolor="#FFFFFF" scope="col" width="100" ><?php echo $this->strWeekAgo;?></th> 
    <th bgcolor="#FFFFFF" scope="col" width="80" >Sales/Last Week</th>
    <th bgcolor="#FFFFFF" scope="col" width="100" >Sales/Target</th>
    <th bgcolor="#FFFFFF" scope="col" width="100" >Cycle Target</th>
    <th bgcolor="#FFFFFF" scope="col" >Shop</th>
    <th bgcolor="#FFFFFF" scope="col" >Last Week Rank</th>
    <th bgcolor="#FFFFFF"  width="300" >&nbsp;</th>
    <th bgcolor="#FFFFFF" scope="col" >Repair Rank</th>
    <th bgcolor="#FFFFFF" scope="col" width="100" >Repair Amount</th>
    <th bgcolor="#FFFFFF" scope="col" width="100" >B Price<br/>Total</th>
    <th bgcolor="#FFFFFF" scope="col" width="100" >Profit %</th>
    <th bgcolor="#FFFFFF" scope="col" width="80" >Repair precent</th>
    <th bgcolor="#FFFFFF" scope="col" width="100" >LastRepair Amount</th>
    <th bgcolor="#FFFFFF" scope="col" width="80" >LastRepair precent</th>

    
  </tr>

<?php 
	$sumLastWeek = 0;
	$sumWeekBefore = 0;
	$sumTarget = 0;
	$sumRLastWeek = 0;
	$sumRWeekBefore = 0;
	
	$repairList = $this->repairRank;
	
foreach($this->arrRes2 as $k => $v){	
	$sumLastWeek += $v['lastweek_total_amt'];
	$sumWeekBefore += $v['weekago_total_amt'];
	$sumTarget += $v['week_target'];	
}	
	$avgSale = round(($sumLastWeek-$sumWeekBefore)/$sumWeekBefore*100,2);
	$avgTarget = round(($sumLastWeek-$sumTarget)/$sumTarget*100,2);
	
	$i = 1;
	$rank = 1;
	$repairList = $this->repairRank;
foreach($this->arrRes2 as $k => $v){?>
	
  <tr>
  	<td bgcolor="#FFFFFF"><?php
    $sum = 0;
	$str = "";
	foreach($v['check'] as $v2){
		if($v2){
			$sum++;
			$str .= "*";
			}
		else{
			$str.= "-";
			}	
		}
	?>
      [<a href="#" title="<?php echo $str?>"><?php echo $sum?></a>]
      
    </td>
    <td bgcolor="#FFFFFF"><?php echo $rank++;?></td> <?php //Shop Rank?>
    <td bgcolor="#FFFFFF"><?php echo $k;?></td>	<?php //shop Name?>
    <td bgcolor="#FFFFFF"><?php echo $v['lastweek_total_amt'];//week sales?></td> 
	<td bgcolor="#FFFFFF"><?php echo $v['weekago_total_amt'];//last week sales?></td>
	<td <?php if($v['increase_rate'] >= (round((10 + $avgSale),2))){?>bgcolor="#FFFF33"<?php }elseif ($v['increase_rate']< (round(($avgSale - 10),2))){?>
	bgcolor="#00FFFF"<?php }else{?>bgcolor="#FFFFFF"<?php }?>
	><?php echo $v['increase_rate'];?> %</td>	<?php //percentage sales/lastweek?>
	<td <?php if($v['sale_target_rate'] >= (round((10 + $avgTarget),2))){?>bgcolor="#FFFF33"<?php }elseif ($v['sale_target_rate'] < (round(($avgTarget - 10),2))){?>
	bgcolor="#00FFFF"<?php }else{?>bgcolor="#FFFFFF"<?php }?>> <?php echo $v['sale_target_rate'];?>%</td>	<?php //percentage sale/target?>		
    <td bgcolor="#FFFFFF"> <?php if($v['lastweek_total_amt'] >= $v['week_target']){?><span style="font-weight: bold;color:green" ><?php echo $v['week_target'];?></span><?php }else{?><span style="font-weight: bold;color:red" ><?php echo $v['week_target'];?></span><?php }?> </td> <?php //target?>
	<td bgcolor="#FFFFFF"><?php echo $k;?></td>		<?php //shop?>
    <td bgcolor="#FFFFFF"><?php echo $v['weekago_rank'];?></td>	<?php //last week rank?>
    <td bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF"><?php echo $v['repair_rank']?></td>
    <td bgcolor="#FFFFFF"><?php echo $v['lastweek_repair_amt']?><?php $sumRLastWeek += $v['lastweek_repair_amt'];?></td>
    <td bgcolor="#FFFFFF"><?php if($v['total_bottom'] == 0){ echo "N/A";}else{ ?><a href="http://<?php echo WEB_IP;?>/caaudit/last-week-repair/date_begin/<?php echo $this->dateBegin;?>/date_end/<?php echo $this->dateEnd?>/shopcode/<?php echo $k?>" target="_blank"><?php echo $v['total_bottom']?></a> <?php }?></td>
    <td bgcolor="#FFFFFF"><?php if($v['total_bottom'] == 0){ echo "N/A";}else{ echo round(($v['lastweek_repair_amt'] - $v['total_bottom'])/$v['total_bottom'],2);}?>%</td>
    <td bgcolor="#FFFFFF"><?php echo $v['lastweek_repair_percent']?>%</td>
    <td bgcolor="#FFFFFF"><?php echo $v['weekago_repair_amt']?><?php $sumRWeekBefore += $v['weekago_repair_amt'];?></td>
    <td bgcolor="#FFFFFF"><?php echo $v['weekago_repair_percent']?>%</td>
  </tr>
  
<?php	}?>
  <tr>
    <td colspan="3" bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF"><?php echo $sumLastWeek?></td>
    <td bgcolor="#FFFFFF"><?php echo $sumWeekBefore?></td>
    <td bgcolor="#FFFFFF"><?php echo $avgSale?>%</td>
    <td bgcolor="#FFFFFF"><?php echo $avgTarget?>%</td>
    <td bgcolor="#FFFFFF"><?php echo $sumTarget?></td>
    <td colspan="4" bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF"><?php echo $sumRLastWeek?></td>
    <td colspan = "2" bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF"><?php echo round($sumRLastWeek/$sumLastWeek*100,2)?>%</td>
    <td bgcolor="#FFFFFF"><?php echo $sumRWeekBefore?></td>
    <td bgcolor="#FFFFFF"><?php echo round($sumRWeekBefore/$sumWeekBefore*100,2)?>%</td>
  </tr>
  <tr>
  	<td colspan = "3" bgcolor="#FFFFFF">&nbsp;</td>
  	<td colspan = "2" bgcolor="#FFFFFF">Total</td>
  	<td colspan = "2" bgcolor="#FFFFFF">Avg</td>
  	<td bgcolor="#FFFFFF">Total</td>
  	<td colspan = "4" bgcolor="#FFFFFF">&nbsp;</td>
  	<td bgcolor="#FFFFFF">Total</td>
  	<td colspan = "2" bgcolor="#FFFFFF">&nbsp;</td>
  	<td bgcolor="#FFFFFF">Repair/Sales</td>
  	<td bgcolor="#FFFFFF">Total</td>
  	<td bgcolor="#FFFFFF">Last Repair/Sales</td>
  </tr>
</table>

<br/>

<?php echo $this->strLastWeek." Total Sales:".$sumLastWeek." (including repair sales $".$sumRLastWeek." , occupied ".round($sumRLastWeek/$sumLastWeek*100,2)."%";?><br/>
<?php echo $this->strWeekAgo." Total Sales:".$sumWeekBefore." (including repair sales $".$sumRWeekBefore." , occupied ".round($sumRWeekBefore/$sumWeekBefore*100,2)."%";?>

</div>
<div id = 'table2'>
<table width = "240" border="0" cellspacing="1" cellpadding="5" style="background:#333">
	<tr>
		<th bgcolor="#FFFFFF" width= "100" scope="col" width="300" colspan ="2">Repair Rank List</th>
	</tr>
	<tr>
		<th bgcolor="#FFFFFF">Shop</th>
		<th bgcolor="#FFFFFF">Repair<br/>
		Rank</th>
	</tr>
	
	<?php foreach ($repairList as $k3 => $v3){ ?>
	<tr>
		<td bgcolor="#FFFFFF"><?php echo $k3;?></td>
		<td bgcolor="#FFFFFF"><?php if($v3 == 0){echo "N/A";}else{echo $i++;}?></td>
	</tr>
	<?php }?>
	
</table>

</div>	
</body>
</html>
